import React, { useState } from 'react'
import axios from "axios"
import { useEffect } from 'react'

export default function Duanzi() {
    //创建状态
    let [haha,setHaha]=useState([]);

    //单独模拟 componentDidMount
    useEffect(()=>{
        async function duanzi(){
            let newshuju=await axios.get('http://api.xiaohigh.com/duanzi');
            console.log(newshuju.data);
            //设置数据
            setHaha(newshuju.data);
        }
        //入口
        duanzi();
    },[])

  return (
    <div className='duanzi'>
        <ul>
            {
                haha.map((item)=>{
                    return (
                        <li key={item.id}>
                            <span>{item.text}</span>
                            <h3>{item.name}</h3>
                        </li>
                    )
                })
                
            }
        </ul>
    </div>
  )
}
